-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Json.add and Json.merge operations #129
base: master
Are you sure you want to change the base?
Fix Json.add and Json.merge operations #129
Conversation
* Json.add should return object with added/updated field * Json.merge should work as Map.plus * Json.toList should use Pair to Tuple2 function * Add test cases for add and merge operations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rather think that, after this, both add
and merge
are the same and we should delete one of them.
Apart from that, I'm my opinion, both methods only works on JsObjects
so one of both we should define the methods on each Json
type or move them to JsObject
. This second thing could be discussed on a different issue and done on a different PR if you like
Agreed, However, I'm not sure if The
If we constrain the merge function to JsObjects only, these situations will not able to happen. I'm happy to make these changes, if we can agree on these. |
As it is on this PR, |
I agree to move them to |
@AdrianRaFo @nomisRev How should we proceed? 🤔 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very excited to see contributions to Helios! 👏👏👏
* move add operation from Json to JsObject * add Monoid to Json.merge operation
Hey @nomisRev, Sorry for the delay. Made the changes today, caught up with upstream and integrated the testing changes from arrow test. Please take a look at it, as I'm not sure I got it right. |
|
||
fun JsObject.Companion.semigroup(): JsObjectSemigroup = object : JsObjectSemigroup { } | ||
|
||
fun JsObject.Companion.monoid(): JsObjectMonoid = object : JsObjectMonoid { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm missing JsNull, JsDecimal, JsNumber, and JsBoolean, also maybe we can add a Monoid of Json matching over all these monoids
JsString.eq() | ||
) | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A tests for each monoid?
) | ||
|
||
testLaws( | ||
MonoidLaws.laws( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess Monoid laws also includes Semigroup laws
override fun Option<Json>.combine(b: Option<Json>) = flatMap { a -> b.map { a.merge(it) } } | ||
override fun empty(): Option<Json> = None | ||
} | ||
)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we deleting the Lens law test?
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should be updated, not deleted
@ambrusadrianzh no worries! Thank you for the contributions! I saw @AdrianRaFo already checked out your PR, I can give it a look next week. This week is a little busy with travelling and KotlinConf ;) |
Fixes #118
Changes: